﻿using System.Windows.Forms;
using SdmxMl.Panels;

using SdmxMl.Structure;

namespace SdmxMl.UC
{
    /// <summary> Container panel for Detail view & Annotations manager </summary>
    public partial class ucPanelDetail : UserControl
    {
        #region Internal Members

        private PanelAnnotationList panelAnnotation = null;
        private PanelAttributes panelAttributes = null;

        #endregion

        #region Properties

        public TabControl TabControlPlugin
        {
            get { return tabControlPlugin; }
        }

        public TabControl TabControlDetail
        {
            get { return tabControlDetail; }
        }
        #endregion

        #region C'tor

        public ucPanelDetail()
        {
            InitializeComponent();
            // Create details panels
            panelAttributes = new PanelAttributes();
            panelAnnotation = new PanelAnnotationList();
            this.splitContainerDetail.Panel1.Controls.Add(panelAttributes.BasePanel);
            panelAttributes.BasePanel.Dock = DockStyle.Fill;
            this.panelAnnotContainer.Controls.Add(panelAnnotation.BasePanel);
            panelAnnotation.ButtonCut = this.buttonCut;
            panelAnnotation.ButtonCopy = this.buttonCopy;
            panelAnnotation.ButtonPaste = this.buttonPaste;
        }
        #endregion

        #region Binding

        public void BindFromNode(TreeNode node)
        {
            // Do we need resizing ?
            this.SuspendLayout();
            if (node != null && node.Tag is AttributeTypeList)
            {
                if (splitContainerDetail.Height < 850)
                    splitContainerDetail.SplitterDistance = splitContainerDetail.Height - 115;
            }

            panelAttributes.BindFromNode(node, panelAnnotation);
            this.ResumeLayout();
        }

        public bool UpdateNodeTag(TreeNode node)
        {
            bool error = false;
            if (panelAttributes.UpdateNodeTag(node))
                error = true;
            return error;
        }
        #endregion

        #region Pane selection

        public void SetActivePane(int index)
        {
            tabControlDetail.SelectedIndex = index;
        }
        #endregion

        #region URN of Artefact item

        public string GetArtefactItemUrn()
        {
            return panelAttributes.GetArtefactItemUrn();
        }

        public void SetSelectedItemFromUrn(SdmxMl.Common.UrnParser up)
        {
            panelAttributes.SetSelectedItemFromUrn(up);
        }

        #endregion
    }
}
